home *** CD-ROM | disk | FTP | other *** search
- Path: news.one.net!mcfarlan
- From: rcm@one.net (Ronald C. McFarland)
- Newsgroups: comp.lang.c
- Subject: Re: Watch out! C "gotcha!"
- Date: Thu, 15 Feb 1996 02:13:01 GMT
- Organization: The PC running Linux on the desk over there
- Message-ID: <1996Feb15.021301.2697@cannon.interramp.com>
- References: <4fthhh$7th@blackice.winternet.com>
- NNTP-Posting-Host: port-7-2.access.one.net
-
- mschwarz@winternet.com (Michael Schwarz) is astonished to find that:
-
- > [plain 'ol C labels can be embedded (and used) inside of switch statements]
- >
- >Does anyone know of:
- >
- > [snip]
- >
- >3) The ANSI party line on labels -- is there an ANSI enforcement option
- > that guarantees a warning on a construct like this? (If not, does
- > anyone know how to suggest revisions to the X3-J11 standard?)
-
- Labels embedded inside the body of "switch" statements are perfectly legal.
- This has always been true and, if you think about it, is no different than
- embedding labels inside the bodies of "for" statements, "while" statements,
- or what-have-you statements.
-
- The standard doesn't specify when or where compilers must give *warnings*.
- In fact, there is no such concept in the standard. The standard says that
- the compiler *must* issue diagnostics when presented with certain violations.
- Also, it states that "no diagnostic is required" when presented with others.
-
- It also says that compilers are free to issue any diagnostics that they wish
- at any time, as long as they correctly translate conforming code. So, it
- is left completely up to the compiler writer whether or not it offers a way
- to flag possible mistakes like the one you have described.
-
- ObSillyImplication (1): Given that the standard does not specify what exact
- form diagnostics must take, a conforming compiler could choose to issue its
- diagnostics by flashing the "Caps Lock" LED on your keyboard whenever it
- encounters a syntax error.
-
- ObSillyImplication (2): The wording in the standard w.r.t. diagnostics
- can be summarized as "sometimes the compiler *must* issue a diagnostic and
- it *can* issue diagnostics at any time." So, a conforming compiler could
- be written which always just prints out "Your program might contain one
- or more errors" whenever it gets run. The standard requires nothing more
- than that.
-
- >The thing that scares me the most about this is that either I've never before
- >made this particular mistake or for the last ten years I've been leaving
- >behind a number of ticking code bombs...
-
- This scares you so much because you happened to get bitten by it. But if
- you think about it, this mistake is no worse than many others. Finding
- a bug caused by a mis-spelled "default" label is probably easier than
- finding one where the programmer typed "+" when he meant to type "-".
-
- If nothing else, under Un*x at least, one can
-
- foo% grep "d.*:" *.c
-
- as a quick check for mis-spelled "default" labels.
-
- --
- Ron McFarland
- rcm@one.net
-